package com.cljz.makepassenger.ui.holder;

import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cljz.makepassenger.base.App;
import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.GetUserInfoBean;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by apple on 2017/5/13.
 */

public class GroupMemberListHolder extends ViewHolder {

    @BindView(R.id.civ_member_head_logo)
    CircleImageView civMemberHeadLogo;
    @BindView(R.id.tv_member_nickname)
    TextView tvMemberNickname;
    @BindView(R.id.iv_owner)
    ImageView ivOwner;
    @BindView(R.id.tv_member_num)
    TextView tvMemberNum;
    @BindView(R.id.iv_line)
    ImageView ivLine;

    public GroupMemberListHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);

    }

    public void setData(List<GetUserInfoBean.DataBean> groupMemberList, int position, Boolean isOwner) {
        GetUserInfoBean.DataBean dataBean = groupMemberList.get(position);
        tvMemberNickname.setText(dataBean.getUser_nickname());
        Picasso.with(App.getInstance())
                .load(dataBean.getUser_logo())
                .error(R.mipmap.head_loading)
                .placeholder(R.mipmap.head_loading)
                .into(civMemberHeadLogo);

        if (position == 0) {
            tvMemberNum.setVisibility(View.VISIBLE);
            tvMemberNum.setText(dataBean.getUser_phone());
            ivOwner.setVisibility(View.VISIBLE);
        } else {
            if (position == groupMemberList.size() - 1) {
                ivLine.setVisibility(View.GONE);
            }
            if (isOwner) {
                tvMemberNum.setVisibility(View.VISIBLE);
                tvMemberNum.setText(dataBean.getUser_phone());
            } else {
                tvMemberNum.setVisibility(View.GONE);
            }
            ivOwner.setVisibility(View.GONE);
        }
    }
}
